﻿// -----------------------------------------------------------------------
// <copyright file="PersonTimeInfoViewModelExtensions.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems, 2012. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace MBOP.Website.Helpers
{
	#region Usings

	using System;
	using System.Globalization;

	using MBOP.Core.Entities.Library;
	using MBOP.Helpers.Extensions;
	using MBOP.Website.ViewModels.Tooltips;

	#endregion

	/// <summary>
	/// Defines the extensions of the MBOPortal.Helpers.PersonTimeInfoViewModel.
	/// </summary>
	public static class PersonTimeInfoViewModelExtensions
	{
		/// <summary>
		/// Generates person's time message.
		/// </summary>
		/// <param name="personTimeInfo">The extension class.</param>
		/// <returns>The message, which contains book time information of the current person.</returns>
		public static string GenerateTimeMessage(this PersonTimeInfoViewModel personTimeInfo)
		{
			string message = string.Empty;

			switch (personTimeInfo.SubscriptionState)
			{
				case SubscribeState.Waiting:
					{
						message = string.Format(CultureInfo.InvariantCulture, "{0} is waiting for {1}", personTimeInfo.PersonCommonName, personTimeInfo.StateTime.GetTimeInterval());
						
						break;
					}

				case SubscribeState.History:
					{
						if (personTimeInfo.StateTime == TimeSpan.Zero)
						{
							message = string.Format(CultureInfo.InvariantCulture, "{0} has read this book", personTimeInfo.PersonCommonName);
						}
						else
						{
							message = string.Format(CultureInfo.InvariantCulture, "{0} was reading this book {1}", personTimeInfo.PersonCommonName, personTimeInfo.StateTime.GetTimeInterval());
						}

						break;
					}

				case SubscribeState.Reader:
					{
						message = string.Format(CultureInfo.InvariantCulture, "{0} is reading this book {1}", personTimeInfo.PersonCommonName, personTimeInfo.StateTime.GetTimeInterval());
						
						break;
					}
			}

			return message;
		}
	}
}